Skip to content

SKU with KRE Demo --DO_NOT_MERGE--#1

Open
richardmands wants to merge 3 commits into
masterfrom
sku-with-kre-demo
Open

SKU with KRE Demo --DO_NOT_MERGE--#1
richardmands wants to merge 3 commits into
masterfrom
sku-with-kre-demo

Conversation

@richardmands
Copy link
Copy Markdown
Contributor

@richardmands richardmands commented Mar 31, 2022

Outcome:

Adding a simple SKU / Identifier to transactions while still allowing transactions to be picked up by the ingestor for the KRE.

Explanation:

We can do this by taking advantage of the 'foreign key' part of the Kin Memo:
https://developer.kin.org/docs/how-it-works/#kin-binary-memo-format

The SDKs currently use this to store a reference to an invoice when invoices are passed along with 'submitPayment':
https://developer.kin.org/docs/how-it-works/#invoices

We can see when the foreign key has been used as the memo stored for the transaction looks like this:
RaAFTNHJgbTVzdGBiJWByOSAjKGFyc2BvMmBsJXNzbk=
instead of this:
RaAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
image
Check out https://laboratory.kin.org/memo to see that the memo formats both output correctly from a KRE perspective.
image
image

Here's the transaction (3bM1GzCxmEVAAS6xrzMwzxq7cvYomKVbFMDPh467RvM67SZP9MkdFubtAoDXASC7PotruRaKYryVyUrcRN8qr1Wt) on explorer:
https://explorer.solana.com/tx/3bM1GzCxmEVAAS6xrzMwzxq7cvYomKVbFMDPh467RvM67SZP9MkdFubtAoDXASC7PotruRaKYryVyUrcRN8qr1Wt?

Here it is being picked up on the Kin Developer Portal:
image

KRE

The memo must be recreated correctly or you won't get credit for your transaction from the KRE!

Invoices

When using invoices, the memo does not store the invoice itself, just a reference that is used by Agora to look up the stored invoice. So the invoice itself is not being stored 'on chain'.

To get around this, we can simply encode an identifying string of some kind with a length of 29 characters or less and pass it into the Memo as the foreign key.

Accessing the On-Chain Data

The contents of this memo are not returned by SDK methods that pick up transaction details, e.g. getTransaction. This means you'll have to use Solana directly to get the transaction data and extract the memo.

Once you have the memo, our Npm package kin-tools/kin-memo provides a class KinMemo that can help to extract the foreign key Buffer which can then be decoded back to the original string.

e.g.

import { KinMemo } from '@kin-tools/kin-memo';
const memo = KinMemo.fromB64String('RaAFTNHJgbTVzdGBiJWByOSAjKGFyc2BvMmBsJXNzbk=')
const foreignKeyBuffer = memo?.foreignKey()
const foreignKey = foreignKeyBuffer.toString()
// foreignKey is 'Str must be 29 chars or less.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant